package v1.chapter10.fill;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class FillTest {

	public static void main(String[] args) {
		EventQueue.invokeLater(()->{
			JFrame frame=new FillFrame();
			frame.setTitle("FillTest");
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
		});

	}

}

class FillFrame extends JFrame{
	public FillFrame() {
		add(new FillComponent());
		pack();
	}
}

class FillComponent extends JComponent {
	private static final int DEFAULT_WIDTH = 400;
	private static final int DEFAULT_HEIGHT = 400;

	public void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;

		double leftX = 100;
		double topY = 100;
		double width = 200;
		double height = 150;
		
		Rectangle2D rect=new Rectangle2D.Double(leftX,topY,width,height);
		g2.setPaint(Color.BLACK);
		g2.draw(rect);
		g2.setPaint(Color.red);
		g2.fill(rect);
	}
	
	public Dimension getPreferredSize() {
		return new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT);
	}
}